package com.wobito.system.aspect;

import com.wobito.common.utils.DateUtils;
import com.wobito.common.utils.LoginInfoContext;
import com.wobito.common.utils.StringUtils;
import com.wobito.pojo.vo.log.AddOperateLog;
import com.wobito.service.IOperateLogService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Wangbaba
 * @Date 2024/9/2 11:22
 * @Version 1.0
 */
@Aspect
@Component
public class LogAspect {

    @Autowired
    private IOperateLogService operateLogService;

    @After("@annotation(operLog)")
    public void operLog(JoinPoint joinPoint,OperLog operLog){
        String userName= StringUtils.isEmpty(operLog.username())?LoginInfoContext.getLoginName():operLog.username();
        String thing=operLog.thing();
        operateLogService.insertOperateLog(new AddOperateLog( DateUtils.getYearAndMonth(),userName,thing, DateUtils.getNowDate()));
    }
}
